from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from goods.models import GoodsChannel, GoodsChannelGroup, SpecificationOption, SKU
from order.models import OrderInfo, OrderGoods




class SKUSerializer(ModelSerializer):
    class Meta:
        model = SKU
        fields = ('name','default_image')

class OrderSKUSerializer(ModelSerializer):
    sku = SKUSerializer(read_only=True)

    class Meta:
        model = OrderGoods
        fields = ('count','price','sku')

class OrderGoodsSerializer(ModelSerializer):
    #关联嵌套

    user = serializers.StringRelatedField(read_only=True)
    user_id = serializers.IntegerField()
    skus = OrderSKUSerializer(many=True,read_only=True)

    class Meta:
        model = OrderInfo
        fields = '__all__'


class OrderInfoSerializer(ModelSerializer):

    class Meta:
        model = OrderInfo
        fields = '__all__'